8 changed files with 352 additions and 0 deletions
@ -0,0 +1 @@ |
|||
*.xsd |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="utf-8" ?> |
|||
<configuration> |
|||
<startup> |
|||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /> |
|||
</startup> |
|||
</configuration> |
|||
@ -0,0 +1,22 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item"> |
|||
<TemplateData> |
|||
<DefaultName>CSharpClassTemplate.cs</DefaultName> |
|||
<Name>CSharpClassTemplate</Name> |
|||
<Description>Example template for VsTemplate Designer</Description> |
|||
<ProjectType>CSharp</ProjectType> |
|||
<SortOrder>10</SortOrder> |
|||
<Icon>__TemplateIcon.ico</Icon> |
|||
</TemplateData> |
|||
<TemplateContent> |
|||
<References> |
|||
<Reference> |
|||
<Assembly>Microsoft.CSharp</Assembly> |
|||
</Reference> |
|||
<Reference> |
|||
<Assembly>System</Assembly> |
|||
</Reference> |
|||
</References> |
|||
<ProjectItem SubType="Code" TargetFileName="$fileinputname$.cs" ReplaceParameters="true">Class1.cs</ProjectItem> |
|||
</TemplateContent> |
|||
</VSTemplate> |
|||
@ -0,0 +1,112 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{5658F6CE-8F9D-4A8F-AF8F-0A2D0B7A2749}</ProjectGuid> |
|||
<OutputType>Exe</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>Perspex.Markup.Xaml.Schema.Generator</RootNamespace> |
|||
<AssemblyName>Perspex.Markup.Xaml.Schema.Generator</AssemblyName> |
|||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<PlatformTarget>AnyCPU</PlatformTarget> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<PlatformTarget>AnyCPU</PlatformTarget> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Xml.Linq" /> |
|||
<Reference Include="System.Data.DataSetExtensions" /> |
|||
<Reference Include="Microsoft.CSharp" /> |
|||
<Reference Include="System.Data" /> |
|||
<Reference Include="System.Net.Http" /> |
|||
<Reference Include="System.Xml" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="Program.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<None Include="App.config" /> |
|||
<None Include="perspex.xsd"> |
|||
<SubType>Designer</SubType> |
|||
</None> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\Perspex.Animation\Perspex.Animation.csproj"> |
|||
<Project>{d211e587-d8bc-45b9-95a4-f297c8fa5200}</Project> |
|||
<Name>Perspex.Animation</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Application\Perspex.Application.csproj"> |
|||
<Project>{799a7bb5-3c2c-48b6-85a7-406a12c420da}</Project> |
|||
<Name>Perspex.Application</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Base\Perspex.Base.csproj"> |
|||
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project> |
|||
<Name>Perspex.Base</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Controls\Perspex.Controls.csproj"> |
|||
<Project>{d2221c82-4a25-4583-9b43-d791e3f6820c}</Project> |
|||
<Name>Perspex.Controls</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Input\Perspex.Input.csproj"> |
|||
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project> |
|||
<Name>Perspex.Input</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Layout\Perspex.Layout.csproj"> |
|||
<Project>{42472427-4774-4c81-8aff-9f27b8e31721}</Project> |
|||
<Name>Perspex.Layout</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.ReactiveUI\Perspex.ReactiveUI.csproj"> |
|||
<Project>{6417b24e-49c2-4985-8db2-3ab9d898ec91}</Project> |
|||
<Name>Perspex.ReactiveUI</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.SceneGraph\Perspex.SceneGraph.csproj"> |
|||
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project> |
|||
<Name>Perspex.SceneGraph</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Styling\Perspex.Styling.csproj"> |
|||
<Project>{f1baa01a-f176-4c6a-b39d-5b40bb1b148f}</Project> |
|||
<Name>Perspex.Styling</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Themes.Default\Perspex.Themes.Default.csproj"> |
|||
<Project>{3e10a5fa-e8da-48b1-ad44-6a5b6cb7750f}</Project> |
|||
<Name>Perspex.Themes.Default</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Content Include="CSharpClassTest.vstemplate" /> |
|||
<Content Include="Test.xml"> |
|||
<SubType>Designer</SubType> |
|||
<Generator>MSBuild:Compile</Generator> |
|||
</Content> |
|||
</ItemGroup> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,161 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Reflection; |
|||
using System.Xml; |
|||
using System.Xml.Schema; |
|||
|
|||
namespace Perspex.Markup.Xaml.Schema.Generator |
|||
{ |
|||
public class Program |
|||
{ |
|||
private const string Xs = "http://www.w3.org/2001/XMLSchema"; |
|||
|
|||
const string Namespace = "https://github.com/grokys/Perspex"; |
|||
private static readonly XmlQualifiedName StringType = new XmlQualifiedName("string", Xs); |
|||
private const string TypeSuffix = "PerspexType"; |
|||
static void Main(string[] args) |
|||
{ |
|||
var outputFile = args.Length > 0 ? args[0] : @"..\..\perspex.xsd"; |
|||
|
|||
var schema = new XmlSchema() |
|||
{ |
|||
TargetNamespace = Namespace, ElementFormDefault = XmlSchemaForm.Qualified |
|||
}; |
|||
|
|||
var globalChoice = new XmlSchemaChoice(); |
|||
schema.Items.Add(new XmlSchemaGroup() {Name = "all", Particle = globalChoice}); |
|||
var declared = new HashSet<string>(); |
|||
foreach (var dll in |
|||
Directory.GetFiles(Path.Combine(typeof (Program).Assembly.GetModules()[0].FullyQualifiedName, ".."), |
|||
"*.dll")) |
|||
{ |
|||
foreach (var t in Assembly.LoadFrom(dll).GetTypes()) |
|||
{ |
|||
if (typeof (PerspexObject).IsAssignableFrom(t)) |
|||
{ |
|||
if (!declared.Add(t.Name)) |
|||
continue; |
|||
var ctype = new XmlSchemaComplexType {Name = t.Name + TypeSuffix, IsMixed = true}; |
|||
schema.Items.Add(ctype); |
|||
var element = new XmlSchemaElement() |
|||
{ |
|||
SchemaTypeName = new XmlQualifiedName(t.Name + TypeSuffix, Namespace), |
|||
Name = t.Name |
|||
}; |
|||
schema.Items.Add(element); |
|||
globalChoice.Items.Add(new XmlSchemaElement() |
|||
{ |
|||
RefName = new XmlQualifiedName(element.Name, Namespace) |
|||
}); |
|||
|
|||
var sequence = new XmlSchemaChoice() {MaxOccursString = "unbounded"}; |
|||
ctype.Particle = sequence; |
|||
var hs = new HashSet<string>(); |
|||
foreach (var prop in t.GetProperties()) |
|||
{ |
|||
if (!hs.Add(prop.Name)) |
|||
continue; |
|||
var propType = prop.PropertyType; |
|||
var name = prop.Name; |
|||
|
|||
ctype.Attributes.Add(new XmlSchemaAttribute() |
|||
{ |
|||
Name = prop.Name, |
|||
Use = XmlSchemaUse.Optional, |
|||
SchemaTypeName = ResolveTypeName(propType, true) |
|||
}); |
|||
var subElement = new XmlSchemaElement() |
|||
{ |
|||
// ReSharper disable once PossibleNullReferenceException
|
|||
Name = prop.DeclaringType.Name + "." + prop.Name, |
|||
SchemaTypeName = ResolveTypeName(propType, false), |
|||
MaxOccurs = 1, |
|||
MinOccurs = 0 |
|||
}; |
|||
sequence.Items.Add(subElement); |
|||
} |
|||
sequence.Items.Add(new XmlSchemaGroupRef() {RefName = new XmlQualifiedName("all", Namespace)}); |
|||
} |
|||
if (t.IsEnum) |
|||
{ |
|||
if (!declared.Add(t.Name)) |
|||
continue; |
|||
|
|||
const string EnumTypeSuffix = "Enumeration"; |
|||
|
|||
var restriction = new XmlSchemaSimpleTypeRestriction() {BaseTypeName = StringType}; |
|||
foreach (var name in Enum.GetNames(t)) |
|||
restriction.Facets.Add(new XmlSchemaEnumerationFacet() |
|||
{ |
|||
Value = name |
|||
}); |
|||
schema.Items.Add(new XmlSchemaSimpleType |
|||
{ |
|||
Content = restriction, |
|||
Name = t.Name + TypeSuffix + EnumTypeSuffix |
|||
}); |
|||
|
|||
schema.Items.Add(new XmlSchemaSimpleType() |
|||
{ |
|||
Name = t.Name + TypeSuffix, |
|||
|
|||
Content = new XmlSchemaSimpleTypeUnion() |
|||
{ |
|||
MemberTypes =new[] |
|||
{ |
|||
new XmlQualifiedName(t.Name + TypeSuffix + EnumTypeSuffix, Namespace), |
|||
new XmlQualifiedName("bindingPattern", Namespace), |
|||
} |
|||
} |
|||
}); |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
schema.Items.Add(new XmlSchemaSimpleType() |
|||
{ |
|||
Name = "bindingPattern", |
|||
Content = new XmlSchemaSimpleTypeRestriction() |
|||
{ |
|||
BaseTypeName = StringType, |
|||
Facets = |
|||
{ |
|||
new XmlSchemaPatternFacet() |
|||
{ |
|||
Value = "^{.*}$" |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
|
|||
|
|||
var schemaSet = new XmlSchemaSet(); |
|||
schemaSet.ValidationEventHandler += ValidationCallback; |
|||
schemaSet.Add(schema); |
|||
schemaSet.Compile(); |
|||
|
|||
foreach (XmlSchema s in schemaSet.Schemas()) |
|||
schema = s; |
|||
|
|||
using (var fs = new StreamWriter(outputFile)) |
|||
schema.Write(fs); |
|||
} |
|||
|
|||
private static XmlQualifiedName ResolveTypeName(Type type, bool attribute) |
|||
{ |
|||
if ((!attribute && typeof (PerspexObject).IsAssignableFrom(type)) || (attribute && type.IsEnum)) |
|||
return new XmlQualifiedName(type.Name + TypeSuffix, Namespace); |
|||
|
|||
return StringType; |
|||
} |
|||
|
|||
|
|||
private static void ValidationCallback(object sender, ValidationEventArgs e) |
|||
{ |
|||
Console.WriteLine(e.Message); |
|||
Environment.Exit(1); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyTitle("Perspex.Markup.Xaml.Schema.Generator")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("Perspex.Markup.Xaml.Schema.Generator")] |
|||
[assembly: AssemblyCopyright("Copyright © 2015")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
|
|||
// Setting ComVisible to false makes the types in this assembly not visible
|
|||
// to COM components. If you need to access a type in this assembly from
|
|||
// COM, set the ComVisible attribute to true on that type.
|
|||
[assembly: ComVisible(false)] |
|||
|
|||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|||
[assembly: Guid("5658f6ce-8f9d-4a8f-af8f-0a2d0b7a2749")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="utf-8" ?> |
|||
<Window xmlns="https://github.com/grokys/Perspex" xmlns:my="http://keks-n.net/wat2"> |
|||
<Border VerticalAlignment="Top" HorizontalAlignment="{Binding }"> |
|||
<TextBlock/> |
|||
</Border> |
|||
</Window> |
|||
Loading…
Reference in new issue