本文整理汇总了C#中System.CodeDom.CodeTypeOfExpression类的典型用法代码示例。如果您正苦于以下问题:C# CodeTypeOfExpression类的具体用法?C# CodeTypeOfExpression怎么用?C# CodeTypeOfExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeTypeOfExpression类属于System.CodeDom命名空间,在下文中一共展示了CodeTypeOfExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Serialize
public override object Serialize(IDesignerSerializationManager manager, object value) {
var baseSerializer = (CodeDomSerializer)manager
.GetSerializer(typeof(ResourceManagerSetter).BaseType, typeof(CodeDomSerializer));
object codeObject = baseSerializer.Serialize(manager, value);
var statements = codeObject as CodeStatementCollection;
if (statements != null) {
CodeExpression leftCodeExpression = new CodeVariableReferenceExpression("resources");
var classTypeDeclaration = (CodeTypeDeclaration)manager.GetService(typeof(CodeTypeDeclaration));
CodeExpression typeofExpression = new CodeTypeOfExpression(classTypeDeclaration.Name);
CodeExpression rightCodeExpression =
new CodeObjectCreateExpression(typeof(XafComponentResourceManager),
new[] { typeofExpression });
//CodeExpression rightCodeExpression =
// new CodeTypeReferenceExpression(
// "new DevExpress.ExpressApp.Win.Templates"),
// "XafComponentResourceManager", new[] { typeofExpression });
statements.Insert(0, new CodeAssignStatement(leftCodeExpression, rightCodeExpression));
}
return codeObject;
}
开发者ID:aries544,项目名称:eXpand,代码行数:25,代码来源:ResourceManagerSetter.cs
示例2: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeTypeReference type = new CodeTypeReference ("System.Void");
CodeTypeOfExpression ctm = new CodeTypeOfExpression (type);
Assert.AreSame (type, ctm.Type, "Type");
ctm.Type = new CodeTypeReference ("System.Int32");
}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:CodeTypeOfExpressionCas.cs
示例3: CodeRectangularArrayCreateExpression
public CodeRectangularArrayCreateExpression(CodeTypeReference createType, params CodeExpression[] lengths)
{
_typeOfExpr = new CodeTypeOfExpression(createType);
_lengths = new CodeNotificationExpressionCollection(Refresh, lengths);
Initialize();
Refresh();
}
开发者ID:Saleslogix,项目名称:SLXMigration,代码行数:7,代码来源:CodeRectangularArrayCreateExpression.cs
示例4: BindingElementExtensionSectionGenerator
internal BindingElementExtensionSectionGenerator(Type bindingElementType, Assembly userAssembly, CodeDomProvider provider)
{
this.bindingElementType = bindingElementType;
this.userAssembly = userAssembly;
this.provider = provider;
string typePrefix = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement));
this.generatedClassName = typePrefix + Constants.ElementSuffix;
this.constantsClassName = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement)) + Constants.ConfigurationStrings;
this.defaultValuesClassName = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement)) + Constants.Defaults;
this.customBEVarInstance = Helpers.TurnFirstCharLower(bindingElementType.Name);
customBEArgRef = new CodeArgumentReferenceExpression(customBEVarInstance);
this.customBETypeRef = new CodeTypeReference(bindingElementType.Name);
this.customBETypeOfRef = new CodeTypeOfExpression(customBETypeRef);
this.customBENewVarAssignRef = new CodeVariableDeclarationStatement(
customBETypeRef,
customBEVarInstance,
new CodeObjectCreateExpression(customBETypeRef));
this.bindingElementMethodParamRef = new CodeParameterDeclarationExpression(
CodeDomHelperObjects.bindingElementTypeRef,
Constants.bindingElementParamName);
}
开发者ID:ssickles,项目名称:archive,代码行数:25,代码来源:BindingElementExtensionSectionGenerator.cs
示例5: Clone
public static CodeTypeOfExpression Clone(this CodeTypeOfExpression expression)
{
if (expression == null) return null;
CodeTypeOfExpression e = new CodeTypeOfExpression();
e.Type = expression.Type.Clone();
e.UserData.AddRange(expression.UserData);
return e;
}
开发者ID:jw56578,项目名称:SpecFlowTest,代码行数:8,代码来源:CodeTypeOfExpressionExtensions.cs
示例6: TypescriptTypeOfExpression
public TypescriptTypeOfExpression(
CodeTypeOfExpression codeExpression,
CodeGeneratorOptions options,
ITypescriptTypeMapper typescriptTypeMapper)
{
_codeExpression = codeExpression;
_options = options;
_typescriptTypeMapper = typescriptTypeMapper;
System.Diagnostics.Debug.WriteLine("TypescriptTypeOfExpression Created");
}
开发者ID:s2quake,项目名称:TypescriptCodeDom,代码行数:10,代码来源:TypescriptTypeOfExpression.cs
示例7: GetCodeExpression
/// <summary>
/// When overridden in a derived class, returns code that is used during page execution to obtain the evaluated expression.
/// </summary>
/// <param name="entry">The object that represents information about the property bound to by the expression.</param>
/// <param name="parsedData">The object containing parsed data as returned by <see cref="M:System.Web.Compilation.ExpressionBuilder.ParseExpression(System.String,System.Type,System.Web.Compilation.ExpressionBuilderContext)" />.</param>
/// <param name="context">Contextual information for the evaluation of the expression.</param>
/// <returns>
/// A <see cref="T:System.CodeDom.CodeExpression" /> that is used for property assignment.
/// </returns>
public override CodeExpression GetCodeExpression( BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context )
{
// from http://msdn.microsoft.com/en-us/library/system.web.compilation.expressionbuilder.getcodeexpression.aspx
Type type1 = entry.DeclaringType;
PropertyDescriptor descriptor1 = TypeDescriptor.GetProperties( type1 )[entry.PropertyInfo.Name];
CodeExpression[] expressionArray1 = new CodeExpression[3];
expressionArray1[0] = new CodePrimitiveExpression( entry.Expression.Trim() );
expressionArray1[1] = new CodeTypeOfExpression( type1 );
expressionArray1[2] = new CodePrimitiveExpression( entry.Name );
return new CodeCastExpression( descriptor1.PropertyType, new CodeMethodInvokeExpression( new CodeTypeReferenceExpression( base.GetType() ), "GetEvalData", expressionArray1 ) );
}
开发者ID:tcavaletto,项目名称:Rock-CentralAZ,代码行数:20,代码来源:FingerprintExpressionBuilder.cs
示例8: Constructor2
public void Constructor2 ()
{
string baseType = "mono";
CodeTypeOfExpression ctoe = new CodeTypeOfExpression (baseType);
Assert.IsNotNull (ctoe.Type, "#1");
Assert.AreEqual (baseType, ctoe.Type.BaseType, "#2");
ctoe = new CodeTypeOfExpression ((string) null);
Assert.IsNotNull (ctoe.Type, "#3");
Assert.AreEqual (typeof (void).FullName, ctoe.Type.BaseType, "#4");
}
开发者ID:nlhepler,项目名称:mono,代码行数:12,代码来源:CodeTypeOfExpressionTest.cs
示例9: GetCodeExpression
public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
{
var expression = new CodeExpression[3];
expression[0] = new CodePrimitiveExpression(entry.Expression.Trim());
expression[1] = new CodeTypeOfExpression(typeof(string));
expression[2] = new CodePrimitiveExpression(entry.Name);
return new CodeCastExpression(typeof(string),
new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(GetType()), "GetEvalData",
expression));
}
开发者ID:benmcevoy,项目名称:FatDividends,代码行数:13,代码来源:FatExpressionBuilder.cs
示例10: Constructor0
public void Constructor0 ()
{
CodeTypeOfExpression ctoe = new CodeTypeOfExpression ();
Assert.IsNotNull (ctoe.Type, "#1");
Assert.AreEqual (typeof (void).FullName, ctoe.Type.BaseType, "#2");
CodeTypeReference type = new CodeTypeReference ("mono");
ctoe.Type = type;
Assert.IsNotNull (ctoe.Type, "#3");
Assert.AreSame (type, ctoe.Type, "#4");
ctoe.Type = null;
Assert.IsNotNull (ctoe.Type, "#5");
Assert.AreEqual (typeof (void).FullName, ctoe.Type.BaseType, "#6");
}
开发者ID:nlhepler,项目名称:mono,代码行数:15,代码来源:CodeTypeOfExpressionTest.cs
示例11: StandardBindingSectionGenerator
internal StandardBindingSectionGenerator(Type standardBindingType, Assembly userAssembly, CodeDomProvider provider)
{
this.standardBindingType = standardBindingType;
this.userAssembly = userAssembly;
this.provider = provider;
this.generatedElementClassName = standardBindingType.Name + Constants.ElementSuffix;
this.constantsClassName = standardBindingType.Name.Substring(0, standardBindingType.Name.IndexOf(TypeNameConstants.Binding)) + Constants.ConfigurationStrings;
this.defaultValuesClassName = standardBindingType.Name.Substring(0, standardBindingType.Name.IndexOf(TypeNameConstants.Binding)) + Constants.Defaults;
this.generatedCollectionElementClassName = standardBindingType.Name + Constants.CollectionElementSuffix;
this.customSBTypeRef = new CodeTypeReference(standardBindingType.Name);
this.customSBTypeOfRef = new CodeTypeOfExpression(customSBTypeRef);
this.bindingMethodParamRef = new CodeParameterDeclarationExpression(
CodeDomHelperObjects.bindingTypeRef,
Constants.bindingParamName);
}
开发者ID:ssickles,项目名称:archive,代码行数:17,代码来源:StandardBindingSectionGenerator.cs
示例12: Generate
public CodeExpression[] Generate(Table table, HardwireCodeGenerationContext generator,
CodeTypeMemberCollection members)
{
List<CodeExpression> initializers = new List<CodeExpression>();
generator.DispatchTablePairs(table.Get("overloads").Table, members, exp =>
{
initializers.Add(exp);
});
var name = new CodePrimitiveExpression((table["name"] as string));
var type = new CodeTypeOfExpression(table["decltype"] as string);
var array = new CodeArrayCreateExpression(typeof(IOverloadableMemberDescriptor), initializers.ToArray());
return new CodeExpression[] {
new CodeObjectCreateExpression(typeof(OverloadedMethodMemberDescriptor), name, type, array)
};
}
开发者ID:InfectedBytes,项目名称:moonsharp,代码行数:19,代码来源:OverloadedMethodMemberDescriptorGenerator.cs
示例13: Constructor1
public void Constructor1 ()
{
CodeTypeReference type1 = new CodeTypeReference ("mono1");
CodeTypeOfExpression ctoe = new CodeTypeOfExpression (type1);
Assert.IsNotNull (ctoe.Type, "#1");
Assert.AreSame (type1, ctoe.Type, "#2");
ctoe.Type = null;
Assert.IsNotNull (ctoe.Type, "#3");
Assert.AreEqual (typeof (void).FullName, ctoe.Type.BaseType, "#4");
CodeTypeReference type2 = new CodeTypeReference ("mono2");
ctoe.Type = type2;
Assert.IsNotNull (ctoe.Type, "#5");
Assert.AreSame (type2, ctoe.Type, "#6");
ctoe = new CodeTypeOfExpression ((CodeTypeReference) null);
Assert.IsNotNull (ctoe.Type, "#7");
Assert.AreEqual (typeof (void).FullName, ctoe.Type.BaseType, "#8");
}
开发者ID:nlhepler,项目名称:mono,代码行数:21,代码来源:CodeTypeOfExpressionTest.cs
示例14: HardwireParameterDescriptor
public HardwireParameterDescriptor(Table tpar)
{
CodeExpression ename = new CodePrimitiveExpression(tpar.Get("name").String);
CodeExpression etype = new CodeTypeOfExpression(tpar.Get("origtype").String);
CodeExpression hasDefaultValue = new CodePrimitiveExpression(tpar.Get("default").Boolean);
CodeExpression defaultValue = tpar.Get("default").Boolean ? (CodeExpression)(new CodeObjectCreateExpression(typeof(DefaultValue))) :
(CodeExpression)(new CodePrimitiveExpression(null));
CodeExpression isOut = new CodePrimitiveExpression(tpar.Get("out").Boolean);
CodeExpression isRef = new CodePrimitiveExpression(tpar.Get("ref").Boolean);
CodeExpression isVarArg = new CodePrimitiveExpression(tpar.Get("varargs").Boolean);
CodeExpression restrictType = tpar.Get("restricted").Boolean ? (CodeExpression)(new CodeTypeOfExpression(tpar.Get("type").String)) :
(CodeExpression)(new CodePrimitiveExpression(null));
Expression = new CodeObjectCreateExpression(typeof(ParameterDescriptor), new CodeExpression[] {
ename, etype, hasDefaultValue, defaultValue, isOut, isRef,
isVarArg }
);
ParamType = tpar.Get("origtype").String;
HasDefaultValue = tpar.Get("default").Boolean;
IsOut = tpar.Get("out").Boolean;
IsRef = tpar.Get("ref").Boolean;
}
开发者ID:InfectedBytes,项目名称:moonsharp,代码行数:23,代码来源:HardwireParameterDescriptor.cs
示例15: BuildExpression
private CodeExpression BuildExpression(XSharpParser.PrimaryExpressionContext expression)
{
CodeExpression expr = null;
XSharpParser.PrimaryContext ctx = expression.Expr;
//
if (ctx is XSharpParser.SelfExpressionContext) // Self
{
expr = new CodeThisReferenceExpression();
}
else if (ctx is XSharpParser.SuperExpressionContext) // Super
{
expr = new CodeBaseReferenceExpression();
}
else if (ctx is XSharpParser.LiteralExpressionContext)
{
XSharpParser.LiteralExpressionContext lit = (XSharpParser.LiteralExpressionContext)ctx;
expr = BuildLiteralValue(lit.Literal);
}
else if (ctx is XSharpParser.LiteralArrayExpressionContext) // { expr [, expr] }
{
XSharpParser.LiteralArrayContext arr = ((XSharpParser.LiteralArrayExpressionContext)ctx).LiteralArray;
// Typed Array ?
if (arr.Type != null)
{
List<CodeExpression> exprlist = new List<CodeExpression>();
foreach (var Element in arr._Elements)
{
exprlist.Add(BuildExpression(Element.Expr,true));
}
expr = new CodeArrayCreateExpression(BuildDataType(arr.Type), exprlist.ToArray());
}
else
{
expr = new CodeSnippetExpression(arr.GetText());
}
}
else if (ctx is XSharpParser.DelegateCtorCallContext)
{
XSharpParser.DelegateCtorCallContext delg = (XSharpParser.DelegateCtorCallContext)ctx;
//
CodeTypeReference ctr = BuildDataType(delg.Type);
CodeExpression ce = BuildExpression(delg.Obj,false);
//
expr = new CodeDelegateCreateExpression(BuildDataType(delg.Type), BuildExpression(delg.Obj,false), delg.Func.GetText());
}
else if (ctx is XSharpParser.CtorCallContext)
{
XSharpParser.CtorCallContext ctor = (XSharpParser.CtorCallContext)ctx;
CodeTypeReference ctr = BuildDataType(ctor.Type);
List<CodeExpression> exprlist = new List<CodeExpression>();
if (ctor.ArgList != null)
{
foreach (var arg in ctor.ArgList._Args)
{
// We should handle arg.Name if arg.ASSIGN_OP is not null...
exprlist.Add(BuildExpression(arg.Expr,false));
}
}
expr = new CodeObjectCreateExpression(ctr.BaseType, exprlist.ToArray());
}
else if (ctx is XSharpParser.TypeOfExpressionContext)
{
CodeTypeReference ctr = BuildDataType(((XSharpParser.TypeOfExpressionContext)ctx).Type);
expr = new CodeTypeOfExpression(ctr);
}
else if (ctx is XSharpParser.NameExpressionContext)
{
String name = ((XSharpParser.NameExpressionContext)ctx).Name.Id.GetText();
// Sometimes, we will need to do it that way....
if (name.ToLower() == "self")
{
expr = new CodeThisReferenceExpression();
}
else if (name.ToLower() == "super")
{
expr = new CodeBaseReferenceExpression();
}
else
{
CodeTypeReference ctr = BuildSimpleName(((XSharpParser.NameExpressionContext)ctx).Name);
expr = new CodeVariableReferenceExpression(name);
}
}
else
{
expr = new CodeSnippetExpression(ctx.GetText());
}
return expr;
}
开发者ID:X-Sharp,项目名称:XSharpPublic,代码行数:90,代码来源:XSharpTreeDiscover.cs
示例16: GenerateTypeOfExpression
/// <devdoc>
/// <para>
/// Generates code for the specified CodeDom based type of expression
/// representation.
/// </para>
/// </devdoc>
private void GenerateTypeOfExpression(CodeTypeOfExpression e) {
Output.Write("typeof(");
OutputType(e.Type);
Output.Write(")");
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:11,代码来源:csharpcodeprovider.cs
示例17: ValidateTypeOfExpression
private static void ValidateTypeOfExpression(CodeTypeOfExpression e) {
ValidateTypeReference(e.Type);
}
开发者ID:uQr,项目名称:referencesource,代码行数:3,代码来源:CodeValidator.cs
示例18: GenerateAndStoreViews
/// <summary>
/// Generates the code to store the views in a C# or a VB file based on the
/// options passed in by the user.
/// </summary>
/// <param name="mappingCollection"></param>
/// <param name="generatedViews"></param>
/// <param name="sourceWriter"></param>
/// <param name="provider"></param>
/// <returns></returns>
private static void GenerateAndStoreViews(StorageMappingItemCollection mappingCollection,
Dictionary<EntitySetBase, string> generatedViews, TextWriter sourceWriter, CodeDomProvider provider, IList<EdmSchemaError> schemaErrors)
{
EdmItemCollection edmCollection = mappingCollection.EdmItemCollection;
StoreItemCollection storeCollection = mappingCollection.StoreItemCollection;
//Create an emtpty compile unit and build up the generated code
CodeCompileUnit compileUnit = new CodeCompileUnit();
//Add the namespace for generated code
CodeNamespace codeNamespace = new CodeNamespace(EntityViewGenerationConstants.NamespaceName);
//Add copyright notice to the namespace comment.
compileUnit.Namespaces.Add(codeNamespace);
foreach (var storageEntityContainerMapping in mappingCollection.GetItems<StorageEntityContainerMapping>())
{
//Throw warning when containerMapping contains query view for bug 547285.
if (HasQueryView(storageEntityContainerMapping))
{
schemaErrors.Add(new EdmSchemaError(
Strings.UnsupportedQueryViewInEntityContainerMapping(storageEntityContainerMapping.Identity),
(int)StorageMappingErrorCode.UnsupportedQueryViewInEntityContainerMapping,
EdmSchemaErrorSeverity.Warning));
continue;
}
#region Class Declaration
string edmContainerName = storageEntityContainerMapping.EdmEntityContainer.Name;
string storeContainerName = storageEntityContainerMapping.StorageEntityContainer.Name;
string hashOverMappingClosure = MetadataMappingHasherVisitor.GetMappingClosureHash(edmCollection.EdmVersion, storageEntityContainerMapping);
StringBuilder inputForTypeNameContent = new StringBuilder(hashOverMappingClosure);
string viewStorageTypeName = EntityViewGenerationConstants.ViewGenerationTypeNamePrefix + StringHashBuilder.ComputeHash(MetadataHelper.CreateMetadataHashAlgorithm(edmCollection.EdmVersion), inputForTypeNameContent.ToString()).ToUpperInvariant();
//Add typeof expression to get the type that contains ViewGen type. This will help us in avoiding to go through
//all the types in the assembly. I have also verified that this works with VB with a root namespace prepended to the
//namespace since VB is picking up the type correctly as long as it is in the same assembly even with out the root namespace.
CodeTypeOfExpression viewGenTypeOfExpression = new CodeTypeOfExpression(EntityViewGenerationConstants.NamespaceName + "." + viewStorageTypeName);
//Add the assembly attribute that marks the assembly as the one that contains the generated views
CodeAttributeDeclaration viewGenAttribute = new CodeAttributeDeclaration(EntityViewGenerationConstants.ViewGenerationCustomAttributeName);
CodeAttributeArgument viewGenTypeArgument = new CodeAttributeArgument(viewGenTypeOfExpression);
viewGenAttribute.Arguments.Add(viewGenTypeArgument);
compileUnit.AssemblyCustomAttributes.Add(viewGenAttribute);
//Add the type which will be the class that contains all the views in this assembly
CodeTypeDeclaration viewStoringType = CreateTypeForStoringViews(viewStorageTypeName);
//Add the constructor, this will be the only method that this type will contain
//Create empty constructor.
CodeConstructor viewStoringTypeConstructor = CreateConstructorForViewStoringType();
viewStoringType.Attributes = MemberAttributes.Public;
//Get an expression that expresses this instance
CodeThisReferenceExpression thisRef = new CodeThisReferenceExpression();
string viewHash = MetadataHelper.GenerateHashForAllExtentViewsContent(edmCollection.EdmVersion, GenerateDictionaryForEntitySetNameAndView(generatedViews));
CodeAssignStatement EdmEntityContainerNameStatement =
new CodeAssignStatement(
new CodeFieldReferenceExpression(thisRef, EntityViewGenerationConstants.EdmEntityContainerName),
new CodePrimitiveExpression(edmContainerName));
CodeAssignStatement StoreEntityContainerNameStatement =
new CodeAssignStatement(
new CodeFieldReferenceExpression(thisRef, EntityViewGenerationConstants.StoreEntityContainerName),
new CodePrimitiveExpression(storeContainerName));
CodeAssignStatement HashOverMappingClosureStatement =
new CodeAssignStatement(
new CodeFieldReferenceExpression(thisRef, EntityViewGenerationConstants.HashOverMappingClosure),
new CodePrimitiveExpression(hashOverMappingClosure));
CodeAssignStatement HashOverAllExtentViewsStatement =
new CodeAssignStatement(
new CodeFieldReferenceExpression(thisRef, EntityViewGenerationConstants.HashOverAllExtentViews),
new CodePrimitiveExpression(viewHash));
CodeAssignStatement ViewCountStatement =
new CodeAssignStatement(
new CodeFieldReferenceExpression(thisRef, EntityViewGenerationConstants.ViewCountPropertyName),
new CodePrimitiveExpression(generatedViews.Count));
viewStoringTypeConstructor.Statements.Add(EdmEntityContainerNameStatement);
viewStoringTypeConstructor.Statements.Add(StoreEntityContainerNameStatement);
viewStoringTypeConstructor.Statements.Add(HashOverMappingClosureStatement);
viewStoringTypeConstructor.Statements.Add(HashOverAllExtentViewsStatement);
viewStoringTypeConstructor.Statements.Add(ViewCountStatement);
//Add the constructor to the type
//.........这里部分代码省略.........
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:101,代码来源:EntityViewGenerator.cs
示例19: Visit
public void Visit (CodeTypeOfExpression o)
{
g.GenerateTypeOfExpression (o);
}
开发者ID:carrie901,项目名称:mono,代码行数:4,代码来源:CodeGenerator.cs
示例20: Serialize
public override object Serialize(IDesignerSerializationManager manager, object obj)
{
if (manager == null)
throw new ArgumentNullException("manager");
if (manager.Context == null)
throw new ArgumentException("manager", SR.GetString(SR.Error_MissingContextProperty));
if (obj == null)
throw new ArgumentNullException("obj");
DependencyObject dependencyObject = obj as DependencyObject;
if (dependencyObject == null)
throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(DependencyObject).FullName), "obj");
Activity activity = obj as Activity;
if (activity != null)
manager.Context.Push(activity);
CodeStatementCollection retVal = null;
try
{
if (activity != null)
{
CodeDomSerializer componentSerializer = manager.GetSerializer(typeof(Component), typeof(CodeDomSerializer)) as CodeDomSerializer;
if (componentSerializer == null)
throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(CodeDomSerializer).FullName));
retVal = componentSerializer.Serialize(manager, activity) as CodeStatementCollection;
}
else
{
retVal = base.Serialize(manager, obj) as CodeStatementCollection;
}
if (retVal != null)
{
CodeStatementCollection codeStatements = new CodeStatementCollection(retVal);
CodeExpression objectExpression = SerializeToExpression(manager, obj);
if (objectExpression != null)
{
ArrayList propertiesSerialized = new ArrayList();
List<DependencyProperty> dependencyProperties = new List<DependencyProperty>(dependencyObject.MetaDependencyProperties);
foreach (DependencyProperty dp in dependencyObject.DependencyPropertyValues.Keys)
{
if (dp.IsAttached)
{
if ((dp.IsEvent && dp.OwnerType.GetField(dp.Name + "Event", BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly) != null) ||
(!dp.IsEvent && dp.OwnerType.GetField(dp.Name + "Property", BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly) != null))
dependencyProperties.Add(dp);
}
}
foreach (DependencyProperty dependencyProperty in dependencyProperties)
{
object value = null;
if (dependencyObject.IsBindingSet(dependencyProperty))
value = dependencyObject.GetBinding(dependencyProperty);
else if (!dependencyProperty.IsEvent)
value = dependencyObject.GetValue(dependencyProperty);
else
value = dependencyObject.GetHandler(dependencyProperty);
// Attached property should always be set through SetValue, no matter if it's a meta property or if there is a data context.
// Other meta properties will be directly assigned.
// Other instance property will go through SetValue if there is a data context or if it's of type Bind.
if (value != null &&
(dependencyProperty.IsAttached || (!dependencyProperty.DefaultMetadata.IsMetaProperty && value is ActivityBind)))
{
object[] attributes = dependencyProperty.DefaultMetadata.GetAttributes(typeof(DesignerSerializationVisibilityAttribute));
if (attributes.Length > 0)
{
DesignerSerializationVisibilityAttribute serializationVisibilityAttribute = attributes[0] as DesignerSerializationVisibilityAttribute;
if (serializationVisibilityAttribute.Visibility == DesignerSerializationVisibility.Hidden)
continue;
}
// Events of type Bind will go through here. Regular events will go through IEventBindingService.
CodeExpression param1 = null;
string dependencyPropertyName = dependencyProperty.Name + ((dependencyProperty.IsEvent) ? "Event" : "Property");
FieldInfo fieldInfo = dependencyProperty.OwnerType.GetField(dependencyPropertyName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
if (fieldInfo != null && !fieldInfo.IsPublic)
param1 = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(DependencyProperty)), "FromName", new CodePrimitiveExpression(dependencyProperty.Name), new CodeTypeOfExpression(dependencyProperty.OwnerType));
else
param1 = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dependencyProperty.OwnerType), dependencyPropertyName);
CodeExpression param2 = SerializeToExpression(manager, value);
//Fields property fails to serialize to expression due to reference not being created,
//the actual code for fields are generated in datacontext code generator so we do nothing here
if (param1 != null && param2 != null)
{
CodeMethodInvokeExpression codeMethodInvokeExpr = null;
if (value is ActivityBind)
codeMethodInvokeExpr = new CodeMethodInvokeExpression(objectExpression, "SetBinding", new CodeExpression[] { param1, new CodeCastExpression(new CodeTypeReference(typeof(ActivityBind)), param2) });
else
codeMethodInvokeExpr = new CodeMethodInvokeExpression(objectExpression, (dependencyProperty.IsEvent) ? "AddHandler" : "SetValue", new CodeExpression[] { param1, param2 });
retVal.Add(codeMethodInvokeExpr);
// Remove the property set statement for the event which is replaced by the SetValue() expression.
foreach (CodeStatement statement in codeStatements)
{
if (statement is CodeAssignStatement && ((CodeAssignStatement)statement).Left is CodePropertyReferenceExpression)
//.........这里部分代码省略.........
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:101,代码来源:DependencyObjectCodeDomSerializer.cs
注:本文中的System.CodeDom.CodeTypeOfExpression类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论