本文整理汇总了C#中INamedTypeSymbol.GetAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:C# INamedTypeSymbol.GetAttributeValue方法的具体用法?C# INamedTypeSymbol.GetAttributeValue怎么用?C# INamedTypeSymbol.GetAttributeValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INamedTypeSymbol
的用法示例。
在下文中一共展示了INamedTypeSymbol.GetAttributeValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTypeFunction
public JsBlockStatement CreateTypeFunction(INamedTypeSymbol classType, out JsBlockStatement typeInitializer, out JsBlockStatement staticInitializer)
{
var isBuiltIn = classType.IsBuiltIn();
var extraBuiltInExports = classType.GetExtraBuiltInExports();
var explicitBaseType = classType.GetAttributeValue<ITypeSymbol>(Context.Instance.JsAttributeType, "BaseType");
var baseType =
explicitBaseType != null ? Type(explicitBaseType) :
Equals(classType, Context.Instance.ObjectType) ? Js.Reference("Object") :
classType.BaseType == null ? Type(Context.Instance.ObjectType) :
Js.Reference(classType.BaseType.GetTypeName());
// classType.BaseType.HasGenericParameters() ? Js.Reference(classType.BaseType.GetTypeName()) :
// Type(classType.BaseType);
var block = new JsBlockStatement();
JsExpression outerClassType = Js.Reference(classType.GetTypeName());
// Generate type initializer
typeInitializer = new JsBlockStatement();
// typeInitializer.Add(StoreInType(SpecialNames.GetAssembly, Js.Reference(classType.ContainingAssembly.GetAssemblyMethodName())));
// typeInitializer.Add(StoreInPrototype(SpecialNames.TypeField, Js.Reference(SpecialNames.TypeInitializerTypeFunction)));
// typeInitializer.Add(StoreInType(SpecialNames.BaseType, baseType));
if (classType.IsExported() && !classType.IsBuiltIn())
{
// typeInitializer.Add(StoreInPrototype(SpecialNames.TypeName, Js.Reference(SpecialNames.TypeInitializerTypeFunction).Member(SpecialNames.TypeName)));
}
else
{
typeInitializer.Add(StoreInPrototype(SpecialNames.TypeName, Js.Primitive(classType.GetFullName())));
typeInitializer.Add(StoreInType(SpecialNames.TypeName, GetFromPrototype(SpecialNames.TypeName)));
}
if (classType.IsBuiltIn())
typeInitializer.Add(StoreClassGetType());
typeInitializer.Add(StoreClassCreateType(classType));
var containingType = classType.ContainingType;
var typeInitializerFunction = Js.Function(new[] { Js.Parameter(SpecialNames.TypeInitializerTypeFunction), Js.Parameter(SpecialNames.TypeInitializerPrototype) }.Concat(classType.TypeParameters.Select(x => Js.Parameter(x.Name))).Concat(classType.GetAnonymousTypeParameters().Select(x => Js.Parameter(x.Item2))).ToArray()).Body(typeInitializer);
if (!isBuiltIn)
{
var displayName = classType.GetFullName();
var args = new[]
{
Js.Reference(SpecialNames.Assembly),
containingType == null ? (JsExpression)Js.Null() : Js.Reference(SpecialNames.TypeInitializerTypeFunction),
Js.Primitive(displayName),
Js.Primitive(classType.HasOrIsEnclosedInGenericParameters()),
Js.Array(
classType.TypeParameters.Select(x =>
(JsExpression)Js.Reference(SpecialNames.DefineTypeParameter).Invoke(
Js.Reference(SpecialNames.Assembly),
Js.Primitive(x.Name),
Type(x.BaseType ?? Context.Instance.ObjectType, true)
)
)
.Concat(classType.GetAnonymousTypeParameters().Select(x =>
Js.Reference(SpecialNames.DefineTypeParameter).Invoke(
Js.Reference(SpecialNames.Assembly),
Js.Primitive(x.Item2),
Type(x.Item1 ?? Context.Instance.ObjectType, true)
)
))
.ToArray()
),
baseType,
typeInitializerFunction
};
if (classType.ContainingType == null && !classType.IsAnonymousType)
{
block.Assign(Js.Reference(classType.ContainingNamespace.GetFullName()).Member(classType.GetShortTypeName()),
Js.Reference(SpecialNames.Define).Invoke(args));
}
else if (classType.ContainingType != null)
{
outerClassType = Js.Reference(SpecialNames.TypeInitializerTypeFunction).Member(classType.GetShortTypeName());
block.Assign(outerClassType, Js.Reference(SpecialNames.Define).Invoke(args));
}
else
{
block.Assign(Js.Reference(classType.GetTypeName()), Js.Reference(SpecialNames.Define).Invoke(args));
}
}
if (classType.IsBuiltIn())
block.Assign(outerClassType.Member(SpecialNames.TypeInitializer), Js.Reference(SpecialNames.DefineTypeFunction).Invoke(outerClassType, typeInitializerFunction));
Func<JsExpression, JsExpression> primaryTypeInitializerCall = expression => expression
.Member("call")
.Invoke(
new[]
{
containingType == null ? (JsExpression)Js.Null() : Js.Reference(SpecialNames.TypeInitializerTypeFunction),
outerClassType,
outerClassType.Member("prototype")
}
.Concat(
classType.TypeParameters.Select(x =>
Js.Reference(SpecialNames.DefineTypeParameter).Invoke(
Js.Reference(SpecialNames.Assembly),
Js.Primitive(x.Name),
Type(x.BaseType ?? Context.Instance.ObjectType, true)
//.........这里部分代码省略.........
示例2: StoreClassCreateType
public JsExpressionStatement StoreClassCreateType(INamedTypeSymbol type)
{
var explicitName = type.GetAttributeValue<string>(Context.Instance.JsAttributeType, "Name");
var fullTypeName = type.GetFullName();
var baseType = type.BaseType != null ? Type(type.BaseType, true) : Js.Null();
var body = new JsBlockStatement();
body.Assign(Js.This().Member(SpecialNames.TypeField),
CreateObject(Context.Instance.TypeConstructor, Js.Primitive(type.Name), CreateAttributes(type)));
TypeFlags typeFlags = 0;
if (type.ContainingType == null)
{
switch (type.DeclaredAccessibility)
{
case Accessibility.Public:
typeFlags |= TypeFlags.Public;
break;
case Accessibility.Internal:
typeFlags |= TypeFlags.Internal;
break;
default:
throw new Exception();
}
}
else
{
switch (type.DeclaredAccessibility)
{
case Accessibility.Public:
typeFlags |= TypeFlags.Public;
break;
case Accessibility.Internal:
typeFlags |= TypeFlags.Internal;
break;
case Accessibility.Private:
typeFlags |= TypeFlags.Private;
break;
case Accessibility.Protected:
typeFlags |= TypeFlags.Protected;
break;
case Accessibility.ProtectedOrInternal:
typeFlags |= TypeFlags.Private | TypeFlags.Internal;
break;
default:
throw new Exception();
}
}
if (type.TypeKind == TypeKind.Interface)
{
typeFlags |= TypeFlags.Interface;
}
else if (type.TypeKind == TypeKind.Class)
{
typeFlags |= TypeFlags.Class;
}
else if (type.TypeKind == TypeKind.Enum)
{
typeFlags |= TypeFlags.Enum;
}
if (type.IsAbstract)
{
typeFlags |= TypeFlags.Abstract;
}
else if (type.IsSealed)
{
typeFlags |= TypeFlags.Sealed;
}
if (type.IsValueType)
{
typeFlags |= TypeFlags.ValueType;
}
if (type.IsPrimitive())
{
typeFlags |= TypeFlags.Primitive;
}
if (type.IsGenericType || type.IsAnonymousTypeWithTypeParameters())
{
typeFlags |= TypeFlags.GenericType;
}
if (type.TypeParameters.Any())
{
typeFlags |= TypeFlags.GenericTypeDefenition;
}
if (type.TypeKind == TypeKind.TypeParameter)
{
typeFlags |= TypeFlags.GenericParameter;
}
var arguments = new List<JsExpression>
{
Js.Primitive(explicitName ?? fullTypeName), // Param1: fullTypeName
Js.Primitive((int)typeFlags),
Type(type, true),
baseType,
CreateInterfaceReferences(type),
MakeArray(Js.Array(type.TypeParameters.Select(x => Js.Reference(x.Name)).Concat(type.GetAnonymousTypeParameters().Select(x => Js.Reference(x.Item2))).ToArray()), Context.Instance.TypeArray)
};
if (!Context.Instance.Compilation.Assembly.IsReflectionMinimized())
{
//.........这里部分代码省略.........