public EXamlCreateResourceDictionary(EXamlContext context, TypeReference type, string content = null) : base(context, null, type) { if (null != content) { Content = content; } }
public EXamlCreateObject(EXamlContext context, object instance, TypeReference type, MethodDefinition xFactoryMethod, object[] @params = null) : base(context) { if (null == type.Resolve()) { throw new Exception("Type can't be null when create object"); } Instance = instance; Type = type; if (null != @params) { foreach (var obj in @params) { paramsList.Add(obj); } } eXamlContext.eXamlOperations.Add(this); Index = eXamlContext.eXamlCreateObjects.Count; XFactoryMethod = xFactoryMethod; eXamlContext.eXamlCreateObjects.Add(this); }
public EXamlAddEvent(EXamlContext context, EXamlCreateObject instance, EXamlCreateObject element, string eventName, MethodDefinition value) : base(context) { TypeReference typeref; var eventDef = instance.Type.GetEvent(fi => fi.Name == eventName, out typeref); if (null != eventDef) { Instance = instance; Element = element; Value = value; DeclaringType = typeref; this.eventDef = eventDef; Instance.AddEvent(DeclaringType, eventDef); eXamlContext.eXamlOperations.Add(this); eXamlContext.eXamlAddEventList.Add(this); } else { throw new Exception("Property is not element"); } }
public string ConvertToString(List <string> definedAssemblies, List <TypeData> typeDatas) { string ret = ""; int assemblyIndex = definedAssemblies.IndexOf(AssemblyName); if (null == GenericArgumentTypes) { ret += String.Format("(d{0}d \"{1}\")", assemblyIndex, FullName); } else { string strForGenericTypes = "("; foreach (var type in GenericArgumentTypes) { strForGenericTypes += "d" + EXamlContext.GetTypeIndex(type, typeDatas) + "d "; } strForGenericTypes += ")"; ret += String.Format("(d{0}d \"{1}\" {2})", assemblyIndex, FullName, strForGenericTypes); } return(ret); }
public EXamlAddToCollectionProperty(EXamlContext context, EXamlGetObjectByProperty instance, object value) : base(context) { this.instance = instance; this.value = value; eXamlContext.eXamlOperations.Add(this); }
public EXamlAddToCollectionInstance(EXamlContext context, EXamlCreateObject instance, object value) : base(context) { this.instance = instance; this.value = value; eXamlContext.eXamlOperations.Add(this); }
public EXamlRegisterXName(EXamlContext context, object @object, string xName) : base(context) { Instance = @object; XName = xName; eXamlContext.eXamlOperations.Add(this); eXamlContext.xNameToInstance.Add(xName, @object); }
internal EXamlGetObjectByProperty(EXamlContext context, EXamlCreateObject instance, string propertyName) : base(context) { this.instance = instance; this.propertyName = propertyName; eXamlContext.objectsAccordingToProperty.Add(this); eXamlContext.eXamlOperations.Add(this); }
public EXamlAddObject(EXamlContext context, EXamlCreateObject parent, object child, MethodDefinition addMethod) : base(context) { Parent = parent; Child = child; Method = addMethod; eXamlContext.eXamlOperations.Add(this); eXamlContext.eXamlAddObjectList.Add(this); }
public EXamlAddToResourceDictionary(EXamlContext context, EXamlCreateObject @object, string key, object value) : base(context) { instance = @object; this.key = key; this.value = value; eXamlContext.eXamlOperations.Add(this); eXamlContext.resourceDictionary.Add(key, value); }
public EXamlCreateObject(EXamlContext context, TypeReference type) : base(context) { isTypeObject = true; Type = type; eXamlContext.eXamlOperations.Add(this); Index = eXamlContext.eXamlCreateObjects.Count; eXamlContext.eXamlCreateObjects.Add(this); }
public EXamlSetDynamicResource(EXamlContext context, EXamlCreateObject @object, MemberReference bindalbeProperty, string key) : base(context) { this.@object = @object; this.bindableProperty = bindalbeProperty; this.key = key; eXamlContext.eXamlOperations.Add(this); @object.AddBindableProperty(bindableProperty); }
public EXamlSetBindalbeProperty(EXamlContext context, EXamlCreateObject @object, MemberReference bindableProperty, object value) : base(context) { Instance = @object; BindableProperty = bindableProperty; Value = value; Instance.AddBindableProperty(bindableProperty); eXamlContext.eXamlOperations.Add(this); }
public object ProvideValue(EXamlContext context) { object ret = null; context.resourceDictionary.TryGetValue(Key, out ret); if (null == ret) { throw new Exception(String.Format("Key {0} can't be found in Resource", Key)); } return(ret); }
public EXamlSetBinding(EXamlContext context, EXamlCreateObject @object, MemberReference bindableProperty, object binding) : base(context) { Instance = @object; BindableProperty = bindableProperty; Value = binding as EXamlCreateObject; if (null == Value) { throw new Exception($"Can't set binding {binding.ToString()} to {bindableProperty.FullName}"); } eXamlContext.eXamlOperations.Add(this); Instance.AddBindableProperty(bindableProperty); }
public EXamlSetProperty(EXamlContext context, EXamlCreateObject instance, string propertyName, object value) : base(context) { var property = instance.Type.GetProperty(fi => fi.Name == propertyName, out declareTypeRef); if (null != property) { this.instance = instance; this.property = property; this.value = value; if (null != this.instance.Instance) { var propertyInfo = this.instance.Instance.GetType().GetProperty(property.Name); if (value is EXamlCreateObject eXamlCreateObject && null != eXamlCreateObject.Instance) { if (this.instance.Instance is BindingExtension bindingExtension && eXamlCreateObject.Type.FullName == typeof(BindingMode).FullName) { bindingExtension.ModeInEXaml = eXamlCreateObject; } else if (eXamlCreateObject.Type.ResolveCached().IsEnum) { if (eXamlCreateObject.Type.FullName == typeof(BindingMode).FullName) { var realValue = Enum.Parse(typeof(BindingMode), eXamlCreateObject.Instance as string); propertyInfo.SetMethod.Invoke(this.instance.Instance, new object[] { realValue }); } } else { if (instance.GetType().FullName == typeof(Xaml.Build.Tasks.ArrayExtension).FullName && "Type" == propertyName) { eXamlCreateObject.IsValid = false; } propertyInfo.SetMethod.Invoke(this.instance.Instance, new object[] { eXamlCreateObject.Instance }); } } else { propertyInfo.SetMethod.Invoke(this.instance.Instance, new object[] { value }); } }
internal EXamlValueConverterFromString(EXamlContext context, TypeDefinition converterType, string value) { this.context = context; ConverterType = converterType; Value = value; if (!context.typeToInstance.ContainsKey(converterType)) { converterInstance = new EXamlCreateObject(context, null, converterType); context.typeToInstance.Add(converterType, converterInstance); } else { converterInstance = context.typeToInstance[converterType]; } }
public EXamlCreateObject(EXamlContext context, object instance, TypeReference type, object[] @params = null) : base(context) { Instance = instance; Type = type; if (null != @params) { foreach (var obj in @params) { paramsList.Add(obj); } } eXamlContext.eXamlOperations.Add(this); Index = eXamlContext.eXamlCreateObjects.Count; eXamlContext.eXamlCreateObjects.Add(this); }
public EXamlCreateObject ProvideValue(EXamlContext context, ModuleDefinition module) { if (TypedBinding == null) { var typeRef = XmlType.GetTypeReference(XmlTypeExtensions.ModeOfGetType.OnlyGetType, module, null); return(new EXamlCreateObject(context, null, typeRef, new object[] { Path, ModeInEXaml, Converter, ConverterParameter, StringFormat, Source })); } else { throw new Exception("TypedBinding should not be not null"); //TypedBinding.Mode = Mode; //TypedBinding.Converter = Converter; //TypedBinding.ConverterParameter = ConverterParameter; //TypedBinding.StringFormat = StringFormat; //TypedBinding.Source = Source; //TypedBinding.UpdateSourceEventName = UpdateSourceEventName; //TypedBinding.FallbackValue = FallbackValue; //TypedBinding.TargetNullValue = TargetNullValue; //return TypedBinding; } }
public EXamlCreateObject ProvideValue(EXamlContext context, ModuleDefinition module) { if (TypedBinding == null) { var newTypeRef = module.ImportReference(typeof(Tizen.NUI.Binding.Binding)); return(new EXamlCreateObject(context, null, newTypeRef, new object[] { Path, ModeInEXaml, Converter, ConverterParameter, StringFormat, Source })); } else { throw new Exception("TypedBinding should not be not null"); //TypedBinding.Mode = Mode; //TypedBinding.Converter = Converter; //TypedBinding.ConverterParameter = ConverterParameter; //TypedBinding.StringFormat = StringFormat; //TypedBinding.Source = Source; //TypedBinding.UpdateSourceEventName = UpdateSourceEventName; //TypedBinding.FallbackValue = FallbackValue; //TypedBinding.TargetNullValue = TargetNullValue; //return TypedBinding; } }
public static EXamlCreateObject GetStaticInstance(EXamlContext context, TypeReference type, FieldReference field, PropertyReference property) { MemberReference memberRef = null; if (null != field) { memberRef = field; } else if (null != property) { memberRef = property; } if (null == memberRef) { return(null); } if (context.StaticInstances.ContainsKey((type, memberRef))) { return(context.StaticInstances[(type, memberRef)]); }
bool TryCoreCompile(ILRootNode rootnode, EXamlContext visitorContext, out Exception exception) { try { XmlTypeExtensions.s_xmlnsDefinitions?.Clear(); XmlTypeExtensions.s_xmlnsDefinitions = null; visitorContext.Values[rootnode] = new EXamlCreateObject(visitorContext, null, rootnode.TypeReference); rootnode.Accept(new XamlNodeVisitor((node, parent) => node.Parent = parent), null); rootnode.Accept(new EXamlExpandMarkupsVisitor(visitorContext), null); rootnode.Accept(new PruneIgnoredNodesVisitor(), null); rootnode.Accept(new EXamlCreateObjectVisitor(visitorContext), null); rootnode.Accept(new EXamlSetNamescopesAndRegisterNamesVisitor(visitorContext), null); rootnode.Accept(new EXamlSetFieldVisitor(visitorContext), null); rootnode.Accept(new EXamlSetResourcesVisitor(visitorContext), null); rootnode.Accept(new EXamlSetPropertiesVisitor(visitorContext, true), null); exception = null; return(true); } catch (Exception e) { XamlParseException xamlParseException = e as XamlParseException; if (null != xamlParseException) { XamlParseException ret = new XamlParseException(xamlParseException.Message + "\n" + ReferencePath, xamlParseException.XmlInfo, xamlParseException.InnerException); exception = ret; } else { exception = e; } return(false); } }
internal static void WriteOpertions(string filePath, EXamlContext eXamlContext) { var ret = eXamlContext.GenerateEXamlString(); if (string.IsNullOrEmpty(filePath)) { throw new Exception("filePath is empty or null!"); } /*Avoid the difference of '/' in file path on windows and linux*/ filePath = filePath.Replace("\\", "/"); if (filePath.Contains("/")) { OutputDir = filePath.Substring(0, filePath.LastIndexOf("/")); } if (!Directory.Exists(OutputDir)) { Directory.CreateDirectory(OutputDir); } var stream = File.CreateText(filePath); stream.Write(ret); stream.Close(); }
public EXamlCreateObject ProvideValue(IElementNode node, ModuleDefinition module, EXamlContext Context) { INode ntype; if (!node.Properties.TryGetValue(new XmlName("", "Member"), out ntype)) { ntype = node.CollectionItems[0]; } var member = ((ValueNode)ntype).Value as string; if (IsNullOrEmpty(member) || !member.Contains(".")) { var lineInfo = node as IXmlLineInfo; throw new XamlParseException("Syntax for x:Static is [Member=][prefix:]typeName.staticMemberName", lineInfo); } var dotIdx = member.LastIndexOf('.'); var typename = member.Substring(0, dotIdx); var membername = member.Substring(dotIdx + 1); var typeRef = module.ImportReference(XmlTypeExtensions.GetTypeReference(typename, module, node as BaseNode)); var fieldRef = GetFieldReference(typeRef, membername, module); var propertyDef = GetPropertyDefinition(typeRef, membername, module); var ret = EXamlCreateObject.GetStaticInstance(Context, typeRef, fieldRef, propertyDef); if (null == ret) { throw new XamlParseException($"{membername} is not static member in type {typename}", node as IXmlLineInfo); } return(ret); }
public EXamlCreateArrayObject(EXamlContext context, TypeReference type, List <object> items) : base(context, null, type) { this.items = items; }
public EXamlAddToResourceDictionary(EXamlContext context, EXamlCreateObject @object, EXamlCreateObject value) : base(context) { eXamlContext.eXamlOperations.Add(this); }
bool GenerateEXaml(string xamlFilePath, ModuleDefinition module, out IList <Exception> thrownExceptions) { thrownExceptions = null; LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Parsing Xaml"); Stream xamlStream = File.Open(xamlFilePath, FileMode.Open); string className; if (!CecilExtensions.IsXaml(xamlStream, module, out className)) { thrownExceptions.Add(new Exception($"{xamlFilePath} is not xaml format file")); } xamlStream.Seek(0, SeekOrigin.Begin); var typeDef = module.GetTypeDefinition(className); if (null == typeDef) { throw new Exception($"Can't find type \"{className}\" in assembly \"{module.Assembly.FullName}\""); } var rootnode = ParseXaml(xamlStream, typeDef); xamlStream.Close(); if (rootnode == null) { LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}failed."); return(false); } LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}done."); hasCompiledXamlResources = true; LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing {0}.InitializeComponent ()"); Exception e; var visitorContext = new EXamlContext(typeDef, module, null); if (!TryCoreCompile(rootnode, visitorContext, out e)) { LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}failed."); (thrownExceptions = thrownExceptions ?? new List <Exception>()).Add(e); if (e is XamlParseException xpe) { LoggingHelper.LogError(null, null, null, xamlFilePath, xpe.XmlInfo.LineNumber, xpe.XmlInfo.LinePosition, 0, 0, xpe.Message, xpe.HelpLink, xpe.Source); } else if (e is XmlException xe) { LoggingHelper.LogError(null, null, null, xamlFilePath, xe.LineNumber, xe.LinePosition, 0, 0, xe.Message, xe.HelpLink, xe.Source); } else { LoggingHelper.LogError(null, null, null, xamlFilePath, 0, 0, 0, 0, e.Message, e.HelpLink, e.Source); } if (null != e.StackTrace) { LoggingHelper.LogMessage(Low, e.StackTrace); } return(false); } else { var examlDir = outputRootPath + @"res/examl/"; if (Directory.Exists(examlDir)) { Directory.CreateDirectory(examlDir); } var examlFilePath = examlDir + typeDef.FullName + ".examl"; EXamlOperation.WriteOpertions(examlFilePath, visitorContext); } return(true); }
bool GenerateEXaml(TypeDefinition typeDef, EmbeddedResource resource, out IList <Exception> thrownExceptions) { thrownExceptions = null; ModuleDefinition module = typeDef.Module; CustomAttribute xamlFilePathAttr; var xamlFilePath = typeDef.HasCustomAttributes && (xamlFilePathAttr = typeDef.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "Tizen.NUI.Xaml.XamlFilePathAttribute")) != null ? (string)xamlFilePathAttr.ConstructorArguments[0].Value : resource.Name; LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Parsing Xaml"); var rootnode = ParseXaml(resource.GetResourceStream(), typeDef); if (rootnode == null) { LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}failed."); return(false); } LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}done."); hasCompiledXamlResources = true; LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing {0}.InitializeComponent ()"); Exception e; var embeddedResourceNameSpace = GetNameSpaceOfResource(resource); var visitorContext = new EXamlContext(typeDef, typeDef.Module, embeddedResourceNameSpace); if (!TryCoreCompile(rootnode, visitorContext, out e)) { LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}failed."); (thrownExceptions = thrownExceptions ?? new List <Exception>()).Add(e); if (e is XamlParseException xpe) { LoggingHelper.LogError(null, null, null, xamlFilePath, xpe.XmlInfo.LineNumber, xpe.XmlInfo.LinePosition, 0, 0, xpe.Message, xpe.HelpLink, xpe.Source); } else if (e is XmlException xe) { LoggingHelper.LogError(null, null, null, xamlFilePath, xe.LineNumber, xe.LinePosition, 0, 0, xe.Message, xe.HelpLink, xe.Source); } else { LoggingHelper.LogError(null, null, null, xamlFilePath, 0, 0, 0, 0, e.Message, e.HelpLink, e.Source); } if (null != e.StackTrace) { LoggingHelper.LogError(e.StackTrace); } return(false); } else { var examlDir = outputRootPath + @"res/examl/"; if (Directory.Exists(examlDir)) { Directory.CreateDirectory(examlDir); } var examlFilePath = examlDir + typeDef.FullName + ".examl"; EXamlOperation.WriteOpertions(examlFilePath, visitorContext); } return(true); }
public EXamlOperation(EXamlContext eXamlContext) { this.eXamlContext = eXamlContext; }
public EXamlCreateDPObject(EXamlContext context, object value, TypeReference type, string subfix) : base(context, null, type) { this.value = value; this.subfix = subfix; }