本文整理汇总了C#中IMethod.GetDeclaringTypeDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# IMethod.GetDeclaringTypeDefinition方法的具体用法?C# IMethod.GetDeclaringTypeDefinition怎么用?C# IMethod.GetDeclaringTypeDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMethod
的用法示例。
在下文中一共展示了IMethod.GetDeclaringTypeDefinition方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EntityMethodToJsFunctionRef
public static JsMemberExpression EntityMethodToJsFunctionRef(IMethod me)
{
var ownerType = me.GetDeclaringTypeDefinition();
if (Sk.IsGlobalMethod(me))
{
var member = Js.Member(SkJs.GetEntityJsName(me));
return member;
}
else
{
var member = SkJs.EntityToMember(ownerType);
if (!me.IsStatic)
{
if (Sk.IsNativeType(ownerType))
member = member.Member("prototype");
else
member = member.Member("commonPrototype");
}
member = member.Member(SkJs.GetEntityJsName(me));
return member;
}
}
示例2: ExportConstructor
public override JsNode ExportConstructor(IMethod ctor)
{
if (ctor.IsStatic)
{
var globaImporter = CreateGlobalMemberConverter();
var node2 = globaImporter.ExportConstructor(ctor);
return node2;
}
else
{
var func = (JsFunction)base.ExportConstructor(ctor);
var fullname = GetJsTypeName(ctor.GetDeclaringTypeDefinition());
if (fullname.Contains("."))
{
var st = Js.Members(fullname).Assign(func).Statement();
return st;
}
else
{
return Js.Var(fullname, func).Statement();
}
}
}
示例3: GetConstructorBaseOrThisInvocation2
//InvocationExpression GetConstructorBaseOrThisInvocation(IMethod ctor)
//{
// var ctorNode = (ConstructorDeclaration)ctor.GetDeclaration();
// InvocationExpression node = null;
// if (ctorNode != null && ctorNode.Initializer != null && !ctorNode.Initializer.IsNull)
// {
// var xxx = (CSharpInvocationResolveResult)ctorNode.Initializer.Resolve();
// //throw new NotImplementedException();
// //danel
// var baseCtor = xxx.Member;
// var id = new IdentifierExpression(baseCtor.Name);
// id.SetResolveResult(new MemberResolveResult(null, baseCtor));
// node = new InvocationExpression(id);
// node.SetResolveResult(xxx);
// //{ entity = ctorNode.invoked_method, Target = ctorNode.invoked_method.Access() };
// //node.SetResolveResult(
// // node.Arguments.AddRange(ctorNode.Initializer.Arguments);
// }
// else
// {
// var ce = ctor.GetDeclaringTypeDefinition();
// if (Sk.OmitInheritance(ce))
// return null;
// var baseType = GetBaseClassIfValid(ce, true);
// if (baseType != null)
// {
// var baseCtor = baseType.GetConstructor();
// if (baseCtor != null)
// {
// //danel
// //throw new NotImplementedException();
// var id = new IdentifierExpression(baseCtor.Name);
// id.SetResolveResult(new MemberResolveResult(null, baseCtor));
// node = new InvocationExpression(id);// { entity = baseCtor, expression = baseCtor.Access() };
// node.SetResolveResult(new CSharpInvocationResolveResult(null, baseCtor, null));
// }
// }
// }
// return node;
//}
InvocationResolveResult GetConstructorBaseOrThisInvocation2(IMethod ctor)
{
var ctorNode = (ConstructorDeclaration)ctor.GetDeclaration();
InvocationResolveResult node = null;
if (ctorNode != null && ctorNode.Initializer != null && !ctorNode.Initializer.IsNull)
{
var xxx = (CSharpInvocationResolveResult)ctorNode.Initializer.Resolve();
return xxx;
}
else
{
var ce = ctor.GetDeclaringTypeDefinition();
if (Sk.OmitInheritance(ce))
return null;
var baseType = GetBaseClassIfValid(ce, true);
if (baseType != null)
{
var baseCtor = baseType.GetConstructors(t => t.Parameters.Count == 0, GetMemberOptions.IgnoreInheritedMembers).Where(t => !t.IsStatic).FirstOrDefault();
if (baseCtor != null)
{
return baseCtor.AccessSelf().Invoke();
}
}
}
return node;
}
示例4: ShouldExportConstructor
protected bool ShouldExportConstructor(IMethod ctor)
{
var att = ctor.GetMetadata<JsMethodAttribute>();
if (att != null && !att.Export)
return false;
if (ctor.IsGenerated(Compiler.Project) && Sk.OmitDefaultConstructor(ctor.GetDeclaringTypeDefinition()))
return false;
return true;
}
示例5: ExportConstructorParameters
void ExportConstructorParameters(IMethod ctor, JsFunction func)
{
var ce = ctor.GetDeclaringTypeDefinition();
var list = new List<string>();
if (!Sk.IgnoreTypeArguments(ce))
{
//danel
var gprms = ce.TypeParameters.ToList();//.GetGenericArguments().Where(ga => ga.isGenericParam()).ToList();
if (gprms.IsNotNullOrEmpty())
{
var i = 0;
foreach (var gprm in gprms)
{
func.Parameters.Add(gprm.Name);
if (!ctor.IsStatic && func.Block != null)
{
func.Block.Statements.Insert(i, Js.This().Member(gprm.Name).Assign(Js.Member(gprm.Name)).Statement());
i++;
}
}
}
}
var prms = ctor.Parameters;
if (prms != null)
{
func.Parameters.AddRange(prms.Select(t => t.Name));
}
}
示例6: ExportConstructorBody
protected JsBlock ExportConstructorBody(IMethod ctor)
{
var ctorNode = (ConstructorDeclaration)ctor.GetDeclaration();
BlockStatement ccc = null;
if (ctorNode != null)
ccc = ctorNode.Body;
//var ccc = ctor.GetDefinition();//.decl as CsConstructor;
//var ccc = ctor.GetDefinition();
var block2 = (JsBlock)AstNodeConverter.Visit(ccc);
if (block2 == null)
block2 = new JsBlock { Statements = new List<JsStatement>() };
var ce = ctor.GetDeclaringTypeDefinition();
var isClr = Sk.IsClrType(ce);
var isPrototype = Sk.IsNativeType(ce);
var statements = new List<JsStatement>();
//instance fields initializations
if (!Sk.InlineFields(ce))
{
var isGlobal = Sk.IsGlobalType(ce);
var fields = GetExportedDeclaredAndGeneratedFields(ce, ctor.IsStatic);
//var fields = ctor.GetDeclaringTypeDefinition().GetFields(null, GetMemberOptions.IgnoreInheritedMembers).Where(t => t.IsStatic() == ctor.IsStatic).ToList();
//fields = fields.Where(ShouldExportField).ToList();
//fields.AddRange(GeneratePropertyFields(ctor.DeclaringTypeDefinition, ctor.IsStatic));
//var props = ctor.GetDeclaringTypeDefinition().GetProperties(null, GetMemberOptions.IgnoreInheritedMembers).Where(t => t.IsStatic() == ctor.IsStatic).ToList();
//props = props.Where(t=>Sk.IsNativeField(t)).ToList();
//props = props.Where(t => Sk.IsJsExported(t)).ToList();
//var fieldsAndProperties = fields.Cast<IEntity>().Concat(props.Cast<IEntity>());
var initializers = fields.Select(fe => ExportInitializer(fe, null, isGlobal, false)).Cast<JsStatement>().ToList();
if (initializers.Contains(null))
Log.Warn("Some field initializers were not exported");
statements.AddRange(initializers.Where(t => t != null));
}
if (!ctor.IsStatic)
{
//base/this ctor invocation
var invocation = GetConstructorBaseOrThisInvocation2(ctor);
if (invocation != null)
{
var baseThisCe = invocation.Member.DeclaringType;
var isBaseClr = Sk.IsClrType(baseThisCe.GetDefinition());
var isBasePrototype = Sk.IsNativeType(baseThisCe.GetDefinition()) && !Sk.IsJsonMode(baseThisCe.GetDefinition()) && !Sk.IsGlobalType(baseThisCe.GetDefinition());//happens when prototype inherits from json
if (isBaseClr == isClr && isBasePrototype == isPrototype) //base and derived are both prototype, or both are clr
{
var newObjExp2 = AstNodeConverter.VisitExpression(invocation);
JsInvocationExpression invocation2;
if (newObjExp2 is JsNewObjectExpression)
{
var newObjExp = (JsNewObjectExpression)newObjExp2;
invocation2 = newObjExp.Invocation;
}
else if (newObjExp2 is JsInvocationExpression)
{
invocation2 = (JsInvocationExpression)newObjExp2;
}
else
{
throw new Exception("Unexpected node: " + newObjExp2);
}
if (Sk.IsExtJsType(ce))
{
var invocation3 = Js.This().Member("callParent").Invoke();
if (invocation2.Arguments.IsNotNullOrEmpty())
invocation3.Arguments = new List<JsExpression> { Js.NewJsonArray(invocation2.Arguments.NotNull().ToArray()) };
statements.Add(invocation3.Statement());
}
else
{
JsRefactorer.ToCallWithContext(invocation2, new JsThis());
statements.Add(invocation2.Statement());
}
}
}
}
if (block2.Statements == null)
block2.Statements = new List<JsStatement>();
block2.Statements.InsertRange(0, statements);
return block2;
}
示例7: NeedsJsOverloadSuffix
static bool NeedsJsOverloadSuffix(IMethod me)
{
if (Sk.ForceMethodSuffix(me))
return true;
if (me.IsIndexerAccessor()) //TODO: HACK: bug with metaspec - base_type is null in overridden indexer methods
{
//var x = me.HasFlag(entity_flags.f_override);
//var y = me.HasFlag(entity_flags.f_method_Virtual);
return true;
}
if (me.Parameters.IsNullOrEmpty())
return false;
var ce = me.GetDeclaringTypeDefinition();
if (me.IsConstructor)
{
//var ctors = ce.GetConstructors().Where(t => !t.IsGenerated()).ToList(); //isGenerated - metaspec bug? parser generates empty ctor when a ctor with parameters is written
var ctors = ce.GetConstructors().ToList(); //removed "IsGenerated" removed, because of default constructor of structs
if (ctors.Count > 1)
{
if (ctors.Any((m) => m.IsInternal))
{
if (!me.IsInternal && ctors.Count((m) => !m.IsInternal) == 1) return false;
}
return true;
}
return false;
}
var bm = me.GetBaseMethod();
if (bm != null)
return NeedsJsOverloadSuffix(bm);
if (ce != null)
{
var methods = ce.GetAllMethods(me.Name).Where(t => !t.IsExplicitInterfaceImplementation).ToList();
if (methods.Count == 1)
return false;
}
return true;
}
示例8: GetLongFunctionName
internal static string GetLongFunctionName(IMethod me)
{
var x = me.GetDeclaringTypeDefinition().GetEntityJsName(false).Replace('.', '$');
return String.Join("$", x, GetEntityJsName(me));
}
示例9: ExportMethod
public override JsNode ExportMethod(IMethod me)
{
if (Sk.IsGlobalMethod(me))
{
return CreateGlobalMemberConverter().ExportMethod(me);
}
var node = base.ExportMethod(me);
if (node == null)
return node;
if (!node.Is(JsNodeType.Function))
return node;
var func = (JsFunction)node;
func.Name = null;
var ce = me.GetDeclaringTypeDefinition();
var member = ExportTypePrefix(ce, me.IsStatic);
member = member.Member(SkJs.GetEntityJsName(me));
if (LongFunctionNames)
func.Name = SkJs.GetLongFunctionName(me);
var st = member.Assign(func).Statement();
return st;
}